package com.sdry.web.controller.jyy;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sdry.model.lz.Identifyingcode;
import com.sdry.service.jyy.ReceiveService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.lz.Customer;
import com.sdry.model.lz.Warehouse;
import com.sdry.model.zc.ZcGeneralQueryEntity;
import com.sdry.model.zc.ZcSysUserEntity;
import com.sdry.service.jyy.ReceiveDetailService;
import com.sdry.service.jyy.SimpleServise;
import com.sdry.service.lz.CustomerService;
import com.sdry.service.lz.StockOutOrderService;
import com.sdry.service.lz.WarehouseService;
import com.sdry.service.zc.ZcSystemService;

/**
 * 
 * @ClassName StockOutController
 * @Description 入库单跳转菜单
 * @Author lz
 * @Date 2019年3月5日 10:39:13
 * @Version 1.0
 */
@Controller
@RequestMapping("/jyJumpPageMenu")
public class JyJumpPageMenu {

	@Resource
	CustomerService  customerService;
	@Resource
	StockOutOrderService stockOutService;
	@Resource
	WarehouseService warehouseService;
	/**批量库存操作业务层*/
 	@Resource
 	SimpleServise simpleServise;
 	@Resource
 	ReceiveDetailService receiveDetailService;
 	@Resource
	ZcSystemService zcSystemService;
 	@Resource
	ReceiveService receiveService;
 	
	//收货
	@RequestMapping("/receivingNote")
	public String receivingNote(Model model,HttpSession session,HttpServletResponse response){
		
		Long warehouse_id = (Long) session.getAttribute("warehouse_id");
		Warehouse warehouse = new Warehouse();
		
		if(warehouse_id != null) {
			//根据仓库id查询仓库信息
			 warehouse = warehouseService.queryWarehouse(warehouse_id);
		}else {
			warehouse.setCharger("");
			warehouse.setChargertel("");
		}
		
		ZcSysUserEntity staf = (ZcSysUserEntity) session.getAttribute("user");
		 if(staf.getRoleId().equals("20010,")) {
			Customer customer = customerService.queryCustomerlxrById(staf.getCustomer_id());
			/*分仓库查询所有识别码*/
			List<Identifyingcode> identifyingcodeList = receiveService.queryAllIdentifyingcode(warehouse_id);
			model.addAttribute("identifyingcodeList", identifyingcodeList);
			model.addAttribute("charger", warehouse.getCharger());
			model.addAttribute("chargertel", warehouse.getChargertel());
			model.addAttribute("cname", customer.getCustomer_name());
			model.addAttribute("cid", staf.getCustomer_id());
			model.addAttribute("sid", staf.getCustomer_id());
			model.addAttribute("lname", customer.getContacts_name());
			return "/jy/receiving/receivingNote2";
		 } else {
			//List<Customer> customer_type0 = stockOutService.queryAllCustomerByType();
			List<Customer> allCustomerList = simpleServise.selectAllCustomerListByCodeType2(warehouse_id);
			/*分仓库查询所有识别码*/
			List<Identifyingcode> identifyingcodeList = receiveService.queryAllIdentifyingcode(warehouse_id);
			model.addAttribute("identifyingcodeList", identifyingcodeList);
			model.addAttribute("charger", warehouse.getCharger());
			model.addAttribute("chargertel", warehouse.getChargertel());
			model.addAttribute("customer_type0", allCustomerList);
			return "/jy/receiving/receivingNote";
		 }
	}
	
	/**
	 * 去上架页面
	 * @return
	 */
	@RequestMapping("/toUp")
	public String toUp(Model model) {
		/*ZcGeneralQueryEntity zcGeneralQueryEntity = new ZcGeneralQueryEntity();
		List<Warehouse> allWarehouseList = zcInventoryManagementService.selectAllWarehouseList(zcGeneralQueryEntity);
		model.addAttribute("allWarehouseList", allWarehouseList);*/
		return "jy/up/up";
	}

	/**
	 * 质检管理
	 * @return
	 */
	@RequestMapping("/receiveDetailQuality")
	public String receiveDetailQuality () {
		return "jy/receiveDetailQuality/receiveDetailQuality";
	}
	
	/**
	 * 批量入库的发货退回
	 * @author LZ
	 * @date 2019年11月12日 09:29:03
	 * @return
	 */
	@RequestMapping("/deliveryReturned")
	public String deliveryReturned (HttpSession session, Model model) {
		ZcGeneralQueryEntity zcGeneralQueryEntity = new ZcGeneralQueryEntity();
		Long warehouseId = (Long) session.getAttribute("warehouse_id");
		List<Customer> customerList1 = receiveDetailService.queryThisWarehouseCustomer(warehouseId);
		model.addAttribute("customerList1", customerList1);
		// 查询所有人员
		List<ZcSysUserEntity> allSysUserList = zcSystemService.selectAllSysUserList(zcGeneralQueryEntity);
		model.addAttribute("allSysUserList", allSysUserList);
		return "jy/receiveDetailQuality/deliveryReturned";
	}
	
	/**
	 * 精简入库的发货退回
	 * @author LZ
	 * @date 2019年11月12日 09:29:03
	 * @return
	 */
	@RequestMapping("/deliveryReturnedSingle")
	public String deliveryReturnedSingle (HttpSession session, Model model) {
		ZcGeneralQueryEntity zcGeneralQueryEntity = new ZcGeneralQueryEntity();
		Long warehouseId = (Long) session.getAttribute("warehouse_id");
		List<Customer> customerList1 = receiveDetailService.queryThisWarehouseCustomer(warehouseId);
		model.addAttribute("customerList1", customerList1);
		// 查询所有人员
		List<ZcSysUserEntity> allSysUserList = zcSystemService.selectAllSysUserList(zcGeneralQueryEntity);
		model.addAttribute("allSysUserList", allSysUserList);
		return "jy/receiveDetailQuality/deliveryReturnedSingle";
	}

	/**
	 * 电线条码收货入库
	 * @author LZ
	 * @date 2019年11月12日 09:29:03
	 * @return
	 */
	@RequestMapping("/lineReceive")
	public String lineReceive (HttpSession session, Model model) {
		ZcGeneralQueryEntity zcGeneralQueryEntity = new ZcGeneralQueryEntity();
		Long warehouseId = (Long) session.getAttribute("warehouse_id");
		List<Customer> customerList1 = receiveDetailService.queryThisWarehouseCustomer(warehouseId);
		model.addAttribute("customerList1", customerList1);
		// 查询所有人员
		List<ZcSysUserEntity> allSysUserList = zcSystemService.selectAllSysUserList(zcGeneralQueryEntity);
		model.addAttribute("allSysUserList", allSysUserList);
		return "jy/lineReceive/lineReceive";
	}
}
